package com.wgchao.identityrightsmanagement.domain.resource.model;

import com.wgchao.identityrightsmanagement.domain.IdentifiedDomainObject;
import com.wgchao.identityrightsmanagement.domain.ValueObject;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @ClassName: FunctionResources
 * @author: wgchao
 * @createTime: 2020/6/9 3:51 PM
 * @Description: 功能
 */
@Getter
@AllArgsConstructor
public class FunctionResources extends IdentifiedDomainObject {

    private FuncIdentify identify;

    private String funcName;

    public FunctionResources(String menuMark, String funcMark, String funcName) {
        this.identify = new FuncIdentify(menuMark, funcMark);
        this.funcName = funcName;
    }


    public FunctionResources(long id, String menuMark, String funcMark, String funcName, long version) {
        setId(id);
        this.identify = new FuncIdentify(menuMark, funcMark);
        this.funcName = funcName;
        setVersion(version);
    }

    /**
     * 修改功能名称
     * @param updator
     */
    public void modifyFuncName(FuncResourcesUpdator updator){
        if(updator.getFuncName() != null){
            this.funcName = updator.getFuncName().orElse(null);
        }
    }

    public boolean belongToMenu(String menuMark){
        return this.identify.belongToMenu(menuMark);
    }
}
